package org.hotpotmaterial.codegenn2.controller;

import java.util.Set;

import org.hotpotmaterial.codegenn2.dto.DataSourceDTO;
import org.hotpotmaterial.codegenn2.service.IReloadDatasource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

@RestController
@AllArgsConstructor
@RequestMapping("/hmteam/codegen/v1/datasources")
@Api(value = "数据源测试Controller", tags={"数据源测试"})
public class LoadController {

	@Autowired
	private IReloadDatasource reloadDatasource;

	@GetMapping
	@ApiOperation("获取当前所有数据源")
	public Set<String> now() {
		return reloadDatasource.getAllDatasourcesName();
	}

	@PostMapping("/addDruid")
	@ApiOperation("基础Druid数据源")
	public Set<String> addDruid(@Validated @RequestBody DataSourceDTO dto) {
		return reloadDatasource.addDatasource(dto);
	}

	@DeleteMapping
	@ApiOperation("删除数据源")
	public String remove(String name) {
		reloadDatasource.removeDatasource(name);
		return "删除成功";
	}
}
